package dyyx.util;

import java.util.Set;
import java.util.TreeSet;

public class GetAllProcFilesFromDstatCode{
	
	
	private static final String START = "'/proc/";
	private static final String END = "'";
	
	private static final int START_LEN = START.length();

	private static final int END_LEN = END.length();

	
	public static void main(final String[] args) throws Exception{
		// '/proc/stat'
		String file = "/Users/dugang/fun/hellocode/web/code/dstat/dstat";
		
		String str = CommUtil.read(file, null);
		
		int startIndex = -1;
		int endIndex = -1;
	
		/*
		System.out.println(str.indexOf("d"));
		System.out.println(str.indexOf("d",0));
		System.out.println(str.indexOf("d",1));

		*/
		
		// str = "a'/proc/a',,, '/proc/b'1234";
		int searchStartIndex = 0;
		String item = null;
		
		Set<String> set = new TreeSet<String>();
		
		while(true){
			
			startIndex = str.indexOf(START,searchStartIndex);
			if(startIndex<0){
				break;
			}
			endIndex = str.indexOf(END,startIndex + START_LEN);
			if(endIndex < 0){
				break;
			}
			
			searchStartIndex = endIndex + END_LEN;
			item = str.substring(startIndex+1, endIndex);
			//System.out.println(item);
			if(CommUtil.isBlank(item)){
				continue;
			}
			set.add(item);
			
		}
		
		System.out.println(set);
		
		for(String tmp:set){
			System.out.println(tmp);
		}
		
		
	}

}

